You are here: Symbol Reference > Dew Namespace > Dew.Stats Namespace > Dew.Stats.Units Namespace > Classes > StatTimeSerAnalysis Class > StatTimeSerAnalysis Methods > StatTimeSerAnalysis.MovingAverage Method
Dew Stats for .NET
ContentsIndexHome
PreviousUpNext
StatTimeSerAnalysis.MovingAverage Method

Single moving average.

Syntax
C#
Visual Basic
public static double MovingAverage([In] TVec Y, [In] int N, [In] TVec M, out int Index, [In] bool Centered);
Parameters 
Description 
[In] TVec Y 
Sample data. 
[In] int N 
Number of elements in period. 
[In] TVec M 
Smoothed data. 
out int Index 
Index of first value in smoothed data. 
[In] bool Centered 
If true, a centered moving average is perfomed. 

MSE.

Performs single moving average smoothing on data Y. General equation for moving average smoothing is: 

 

where N indicates number of points in period and X.Length data sample size. When using single moving average smoothing, bear in mind that when used as forecasts for the next period, single moving average is not able to cope with a significant trend.

Load sample time series, perform centered moving average smoothing with period 12 (yearly average) and finally plot the results using TChart.

using Dew.Math; using Dew.Stats; using Dew.Stats.Units; using Steema.TeeChart; namespace Dew.Examples { private void Example(Styles.Line line1, Styles.Line line2) { Vector ts = new Vector(0); Vector Mv = new Vector(0); int FirstIndex; ts.LoadFromFile("testdata.vec"); MtxVecTee.DrawValues(ts,line1,0.0,1.0); // draw original time series StatTimeSerAnalysis.MovingAverage(ts,12,Mv,out FirstIndex,true); MtxVecTee.DrawValues(Mv,line2,FirstIndex,1.0); // draw MA over original time series } }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!